
clear all
use data/judgeyear.dta

gen electz1 = electtime2 == 0 
gen  electupC = 0
gen  electupU = 0
replace electupC = electz1 & (howretain == "NP" | howretain == "P")
replace electupU = electz1 & (howretain == "U" )

foreach y in numops numdisc numwords numwords_maj_m numtoc_maj_m poscites_m distcites_m negcites_m outstatecites_m discusscites_m quotecites_m {
gen log`y' = log(1+`y')

// state FE 
eststo: quietly areg log`y' i.year i.statefe#c.year 	electupC electupU, absorb(statefe) 	vce(cluster statefe)
// judge FE
eststo: quietly areg log`y' i.year i.statefe#c.year 	electupC electupU, absorb(judgefe) 	vce(cluster statefe)
// judge FE and state-year FE
eststo: quietly reg2hdfe log`y'  			electupC electupU, id1(stateyearfe) id2(judgefe) cluster(statefe)
}

esttab using tables/elect-cycle.csv, nogaps replace ar2 se drop(_cons *year*) star(+ 0.10 * 0.05 ** 0.01)